import 'package:flutter/material.dart';
import 'package:get/get.dart';

final themeMode = ThemeMode.light.obs;
String changeLanguage(Locale? locales, int index) {
  String languageCode = locales?.languageCode ?? 'en';
  String countryCode = locales?.countryCode ?? 'US';
  String scriptCode = locales?.scriptCode ?? '';
  print(
    '语言切换 index:$index  old:oldLanguageCode: $languageCode  oldCountryCode:$countryCode  scriptCode:$scriptCode',
  );

  if (languageCode == 'zh') {
    if (scriptCode.isNotEmpty &&
        (scriptCode == 'Hant' || scriptCode == 'Hans')) {
      languageCode = '$languageCode$scriptCode';
    } else {
      if (['TW', 'HK', 'MO'].contains(countryCode.toUpperCase())) {
        languageCode = 'zhHant';
      } else {
        languageCode = 'zhHans';
      }
    }
  }

  if (languageCode == 'ru') {
    languageCode = 'ru';
  }

  return languageCode;
}
